// 生成随机股票数据 
function generateStockData(type) {
  const stocks = []
  const baseVol = Math.random()  * 1000000 
  
  for(let i=0; i<10; i++){
    const code = `60${Math.floor(1000  + Math.random()*9000)}` 
    const name = ["茅台","平安","宁德","万科","中兴"][Math.floor(Math.random()*5)]
    const price = (Math.random()*100  + 20).toFixed(2)
    let changeRate, volume 
    
    if(type === 'rise'){
      changeRate = (Math.random()*10  + 0.5).toFixed(2) + '%'
    }else if(type === 'fall'){
      changeRate = (-Math.random()*10  + 0.5).toFixed(2) + '%'
    }else{
      changeRate = (Math.random()*10  -5).toFixed(2) + '%'
    }
    
    volume = (baseVol + Math.random()*500000).toFixed(0) 
    
    stocks.push({ 
      code,
      name,
      price,
      changeRate,
      volume: (volume/10000).toFixed(1)+"万手"
    })
  }
  return stocks 
}
module.exports = {
  generateStockData: generateStockData
};